import axios from '@ohos/axios'
import AccountType from '../viewModel/AccountType'
// let baseUrl= '10.2.2.108'
let baseUrl= '192.168.43.254'
class AccountTypeModel{
  // 查询
  getAccountTypeList(flag:number):Promise<AccountType[]>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'GET',
        // url:'http://localhost:8080/accountType/listAccountType',
        url:'http://'+baseUrl+':8080/accountType/listAccountType',
        params:{
          uid:AppStorage.Get('uid'),
          flag:flag
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('查询失败')
      })
    })
  }
  // 删除
  deleteAccountType(accountType:AccountType):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/accountType/deleteAccountType',
        url:'http://'+baseUrl+':8080/accountType/deleteAccountType',
        data:{
          atid:accountType.atid
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }
//添加种类
  addAccountType(accountType:AccountType):Promise<number>{
    return new Promise((resolve,reject)=>{
      axios({
        method:'POST',
        // url:'http://localhost:8080/accountType/insertAccountType',
        url:'http://'+baseUrl+':8080/accountType/insertAccountType',
        data:{
          atname:accountType.atname,
          isdelete:accountType.isdelete,
          flag:accountType.flag,
          uid:accountType.uid
        },
        headers:{
          'Content-Type': 'application/json',
          'token':AppStorage.Get('token')
        }
      }).then(resp=>{
        if (resp.status == 200) {
          console.log('success',JSON.stringify(resp.data))
          resolve(resp.data)
        }
        else console.log('失败')
        reject('失败')
      })
    })
  }

}
const accountTypeModel = new AccountTypeModel();
export default accountTypeModel as AccountTypeModel;
